package 其他.合并两个数组倒序;

public class DeOrder {
    public static void main(String[] args) {

        int[] a = {1, 3, 5, 6, 6, 7, 8, 78};
        int[] b= {2,3,5,6,8,10};
        int[] ints = reversArray(a, b);
        System.out.print("[");
        for (int i = 0; i < ints.length; i++) {
            System.out.print(ints[i]+",");
        }
        System.out.println("]");

    }
    public static int[] reversArray(int[] a,int [] b){
        int j=a.length-1;
        int k=b.length-1;
        int num=a.length+b.length;

        // 新数组
        int[] c = new int[num];
        int index=0;

        while (j>=0&&k>=0){

            if (a[j]>b[k]){
                c[index]=a[j];
                index++;
                j--;
            }else {
                c[index]=b[k];
                index++;
                k--;
            }
        }
        // 处理剩余部分

        if (j==-1&&k!=-1){
            for (int i = k; i >=0; i--) {
                c[index]=b[i];
                index++;
            }
        }

        if (k==-1&&j!=-1){
            for (int i = j; i >= 0; i--) {
                c[index]=a[i];
                index++;

            }
        }

        return c;

    }
}
